/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gpsmap;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import javazoom.jl.decoder.JavaLayerException;
import javazoom.jl.player.Player;

/**
 * This class plays the help voices
 * refrence: http://www.informit.com/guides/content.aspx?g=java&seqNum=290
 * @author Cyrus Sedaghat, Hadi Oliazadeh
 */
public class MP3Player implements Runnable {

    private Player player;
    private InputStream is;
    boolean bool = true;
    public boolean wait = true;

    /** Creates a new instance of MP3Player */
    public MP3Player(String filename) {
        try {
            // Create an InputStream to the file
            is = new FileInputStream(filename);
            player = new Player(is);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void run() {
        while (true) {

            while (wait) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException ex) {
                    Logger.getLogger(MP3Player.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            
            if(player.isComplete())
                bool = true;
            if (bool) {
                try {
                     wait = true;
                  System.out.println(player.isComplete());
                  player.play();
                  player.close();
                } catch (JavaLayerException ex) {
                    Logger.getLogger(MP3Player.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            wait = true;
        }
    }
}
